package com.android.djlmapp.activity.home.web;

import android.annotation.SuppressLint;
import android.support.constraint.ConstraintLayout;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.android.djlmapp.activity.home.web.base.BaseWebActivity;
import com.android.djlmapp.activity.home.web.base.BaseWebChromeClient;
import com.android.djlmapp.http.ComPareUtils;
import com.android.djlmapp.http.GlobalUrls;
import com.android.djlmapp.token.GetUrlStr;

import butterknife.BindView;

/**
 * 公告详情
 */
public class GongGaoDetailActivity extends BaseWebActivity {

    @BindView(R.id.ll_top_back)
    LinearLayout llTopBack;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.home_iv_readpoint)
    ImageView homeIvReadpoint;
    @BindView(R.id.iv_top_msg)
    ConstraintLayout ivTopMsg;
    @BindView(R.id.iv_top_set)
    ImageView ivTopSet;
    @BindView(R.id.iv_top_kf)
    ImageView ivTopKf;
    @BindView(R.id.page_title_layout)
    ConstraintLayout pageTitleLayout;

    @Override
    protected void initView() {
        setWebViewClient(mWebViewClient);
        llTopBack.setVisibility(View.VISIBLE);
        ivTopMsg.setVisibility(View.GONE);
        ivTopSet.setVisibility(View.GONE);
        ivTopKf.setVisibility(View.VISIBLE);
        tvName.setText("公告详情");
        String ggurl = getIntent().getStringExtra("GGURL");
        String contentId = getIntent().getStringExtra("CONTENT_ID");
        String signUrl = new ComPareUtils.ComPareBuilder()
                .put("content_id", contentId)
                .put("token", getToken())
                .put("version", getVersion())
                .create().getSignString();

        String url = GlobalUrls.MAIN_URL + ggurl + "?content_id=" + contentId +
                "&token=" + getToken() + "&version=" +
                getVersion() + "&sign=" + signUrl;
        Log.e("项目异常", "------公告详情------" + url);
        setWebChromeClient(mDefaultWebChromeClient); // 设置标题

        setWebUrl(url);
        super.initView();
    }

    private WebChromeClient mDefaultWebChromeClient = new BaseWebChromeClient() {
        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            tvName.setText("公告详情");
        }
    };

    private WebViewClient mWebViewClient = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String str) {
            Log.e("项目异常TestWebInterface", "-----DayPriceActivity------" + str);
            if (str.contains("login_out")) {
                GetUrlStr.getStrUrl(GongGaoDetailActivity.this);
                return true;
            } else {
                return false;
            }
        }

        @SuppressLint("NewApi")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            String str = request.getUrl().toString();
            if (str.contains("login_out")) {
                GetUrlStr.getStrUrl(GongGaoDetailActivity.this);
                return true;
            } else {
                return false;
            }
        }
    };
}
